﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Manager_System
{
    public partial class outWH_product : Form
    {
        string name = "";
        string Price = "";//原价格
        string Id = "";
        string Weight = "";//原有重量
        main_form form2;
        public outWH_product(string weight, string id, string price, string sum, main_form form)
        {
            main_form form1 = form;
            Id = id;
            Price = price;
            Weight = weight;
            name = sum;
            //this.name_tb.Text=
            InitializeComponent();
            this.after_tb.Text = Weight.ToString();
            this.name_tb.Text = name;
            this.id_tb.Text = Id;

            this.price_tb.Text = price;
            form2 = form1;
        }

        private void outWH_Load(object sender, EventArgs e)
        {
            
        }
        private void weight_tb_TextChanged(object sender, EventArgs e)
        {
           
        }
            
        private void confirm_bt_Click(object sender, EventArgs e)
        {
           
        
        }

        private void weight_tb_TextChanged_1(object sender, EventArgs e)
        {
            if (this.after_tb.Text != null && this.weight_tb.Text != null && !this.after_tb.Text.Equals("") && !this.weight_tb.Text.Equals(""))
            {
                after_tb.Text = Weight;
                double weight = double.Parse(this.weight_tb.Text);
                double after = double.Parse(this.after_tb.Text);
                after = after - weight;
                if (after <= 0)
                {
          
                    this.after_tb.Text = "0";
                    this.weight_tb.Text = Weight;
                }
                else
                {
                    this.after_tb.Text = after.ToString();
                }
            }
            else
            {
                this.after_tb.Text = Weight;
            }
        }

        private void confirm_bt_Click_1(object sender, EventArgs e)
        {
           
            int w = int.Parse(Weight);

            double p_now = double.Parse(this.price_tb.Text);
            double w_now = double.Parse(this.weight_tb.Text);
            double sum_now = p_now * w_now;
         
          
            form2.recive(p_now.ToString(), after_tb.Text.ToString());
            string sql = "update T_WH_product set Weight=" + after_tb.Text + " where ID=" + this.id_tb.Text + "";
            DBhelp db = new DBhelp();
            int rs = db.update(sql);
            db.close();
            if (rs == 1)
            {
                if (this.after_tb.Text.Equals("0"))
                {
                    string sql1 = "delete from T_WH_product where ID=" + this.id_tb.Text + "";
                    DBhelp db1 = new DBhelp();
                    int rs1 = db1.update(sql1);
                    db1.close();
                    if (rs1 == 1)
                    {
                        MessageBox.Show("出库成功！");
                        form2.clearout();
                    }
                    else
                    {
                        MessageBox.Show("出库失败！");
                    }
                }
                else
                {
                    form2.recive(p_now.ToString(), after_tb.Text.ToString());
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("出库失败！");
            }
        }

        private void close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
